package org.dromara.common.mybatis.util;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.dromara.common.core.utils.BeanCopyUtils;

import java.util.List;

public class PageUtils extends BeanCopyUtils {

    public static <T, V> Page<V> copyPageList(Page<T> sourePage, Class<V> desc) {
        Page<V> pageInfo = new Page<>(sourePage.getCurrent(),sourePage.getSize(),sourePage.getTotal());
        List<V> descList = copyList(sourePage.getRecords(), desc);
        pageInfo.setRecords(descList);
        return pageInfo;
    }


    /**
     * 对象A复制对象B的分页信息 // 多次数据查询导致分页数据异常解决办法
     */
    public static <T> Page<T> copyPageInfo(Page<?> originPageInfo, List<T> list) {
        Page<T> pageInfo = new Page<>(originPageInfo.getCurrent(),originPageInfo.getSize(),originPageInfo.getTotal());
        pageInfo.setRecords(list);
        return pageInfo;
    }
}
